package com.nsgf.library.data.bean;

import com.nsgf.library.utils.StringUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class WaterLevelByCodeBean {

    private InsideType inside;
    private InsideType outside;
    private InsideType rain;

    public InsideType getInside() {
        return inside;
    }

    public void setInside(InsideType inside) {
        this.inside = inside;
    }

    public InsideType getOutside() {
        return outside;
    }

    public void setOutside(InsideType outside) {
        this.outside = outside;
    }

    public InsideType getRain() {
        if (null == rain)
            rain = new InsideType();
        return rain;
    }

    public void setRain(InsideType rain) {
        this.rain = rain;
    }

    public final static class InsideType {
        private String projectCode;
        private String projectCodeDesc;
        private String facilityCode;
        private Object projectName;
        private String facilityName;
        private String rz;
        private String tm;
        private Object children;

        // Constructors
        public InsideType() {
        }


        // 标准 JavaBean getter 方法，用于 DataBinding
        public String getRz() {
            return StringUtil.isEmpty(rz) ? "--" : rz;
        }

        public void setRz(String rz) {
            this.rz = rz;
        }


        // 标准 JavaBean getter 方法，用于 DataBinding
        public String getTm() {
            return tm;
        }

        public void setTm(String tm) {
            this.tm = tm;
        }

        /**
         * 格式化日期为"月日时分"格式，例如：6月30日 14:59
         * 用于 DataBinding
         */
        public String getTmFormatted() {
            if (tm == null || tm.isEmpty()) {
                return "--";
            }
            try {
                // 解析原始日期格式 "yyyy-MM-dd HH:mm:ss" 或 "yyyy-MM-dd HH:mm"
                SimpleDateFormat inputFormat;
                if (tm.length() == 19) {
                    inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
                } else if (tm.length() == 16) {
                    inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault());
                } else {
                    return tm; // 如果格式不匹配，直接返回原值
                }

                Date date = inputFormat.parse(tm);
                if (date != null) {
                    // 格式化为"月日时分"：6月30日 14:59
                    SimpleDateFormat outputFormat = new SimpleDateFormat("M-d HH:mm", Locale.getDefault());
                    return outputFormat.format(date);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return tm;
        }

    }
}

